import pytest
import allure

# 定义一个 fixture，用于提供测试数据
@pytest.fixture(scope="module")
def test_data():
    return {
        "add": [
            (2, 3, 5),
            (-1, 1, 0),
            (0, 0, 0),
            (2.5, 3.5, 6.0),
            (-2, -3, -5)
        ],
        "subtract": [
            (5, 3, 2),
            (-1, 1, -2),
            (0, 0, 0),
            (3.5, 2.5, 1.0),
            (-2, -3, 1)
        ],
        "multiply": [
            (2, 3, 6),
            (-1, 1, -1),
            (0, 5, 0),
            (2.5, 4, 10.0),
            (-2, -3, 6)
        ]
    }

# 基本断言
def assert_result(actual, expected):
    assert actual == expected, f"Expected {expected}, but got {actual}"

# 定义加法函数
def add(a, b):
    """Add two numbers."""
    return a + b

# 定义减法函数
def subtract(a, b):
    """Subtract two numbers."""
    return a - b

# 定义乘法函数
def multiply(a, b):
    """Multiply two numbers."""
    return a * b

# 使用 pytest.mark 标记测试函数
@pytest.mark.smoke
@allure.epic("两数相加")
@allure.feature("加法")
@allure.story("加法")
@allure.title("加法测试")
@allure.description("验证加法功能的正确性")
@allure.severity(allure.severity_level.NORMAL)
def test_add(test_data):
    """Test the add function."""
    for a, b, expected in test_data["add"]:
        actual = add(a, b)
        assert_result(actual, expected)

@pytest.mark.regression
@allure.epic("两数相减")
@allure.feature("减法")
@allure.story("减法")
@allure.title("减法测试")
@allure.description("验证减法功能的正确性")
@allure.severity(allure.severity_level.NORMAL)
def test_subtract(test_data):
    """Test the subtract function."""
    for a, b, expected in test_data["subtract"]:
        actual = subtract(a, b)
        assert_result(actual, expected)

@pytest.mark.regression
@allure.epic("两数相乘")
@allure.feature("乘法")
@allure.story("乘法")
@allure.title("乘法测试")
@allure.description("验证乘法功能的正确性")
@allure.severity(allure.severity_level.NORMAL)
def test_multiply(test_data):
    """Test the multiply function."""
    for a, b, expected in test_data["multiply"]:
        actual = multiply(a, b)
        assert_result(actual, expected)

@pytest.mark.parametrize("a, b, expected", [(2, 3, 5), (-1, 1, 0), (0, 0, 0), (2.5, 3.5, 6.0), (-2, -3, -5)])
def test_add_parametrized(a, b, expected):
    """Test the add function with parameterization."""
    actual = add(a, b)
    assert_result(actual, expected)

@pytest.mark.fast
@allure.epic("两数相减")
@allure.feature("减法")
@allure.story("减法")
@allure.title("减法测试")
@allure.description("验证减法功能的正确性")
@allure.severity(allure.severity_level.NORMAL)
def test_subtract_parametrized(a, b, expected):
    """Test the subtract function with parameterization."""
    a = 5
    b = 3
    actual = subtract(a, b)
    assert_result(actual, expected)